//
//  SGArticleModel.swift
//  songguo
//
//  Created by 潘传洲 on 16/6/11.
//  Copyright © 2016年 pcz. All rights reserved.
//

import UIKit

class SGArticleModel: SGSpecificModel {
    
    
    var desc: String?
    var title: String?
    var user : SGUserModel?
    
    
    class func initWithDict(dict : [String : AnyObject]) -> SGArticleModel {
        
        let article = SGArticleModel()
        article.desc = dict["desc"] as? String
        article.title = dict["title"] as? String
        article.ID = dict["id"] as? String
        
        let resources = SGResourceModel.resourceModels(dict["resource"] as! [[String : AnyObject]])
        var specificViewModels = [SGSpecificViewModel]()
        for resource in resources {
            specificViewModels.append(SGSpecificViewModel.initWithResourceModel(resource))
        }
        article.specificViewModels = specificViewModels
        
        let cover = dict["cover"] as! [String : AnyObject]
        article.coverUrl = cover["url"] as? String
        
        let topImage = dict["topImage"] as! [String : AnyObject]
        article.topImageUrl = topImage["url"] as? String
        
        
        article.user = SGUserModel.initWithDict(dict["user"] as! [String : AnyObject])
        return article
    }

}
